package com.yangcangclub.commons.result;

import com.yangcangclub.commons.exception.ApolloException;

/**
 * 接口返回数据格式
 */
public class ResultData {
    private int code;
    private String msg;
    private Object data=new Object();

    public ResultData() {

    }
    //默认结果
    public static ResultData defaultResult(){
        return new ResultData(MessageEnum.SYSTEM_UNKNOWN_ERROR);
    }
    //不含有业务数据结果集
    public ResultData(MessageEnum msg) {
        this.code = msg.getCode();
        this.msg = msg.getDesc();
    }

    //含有业务数据结果集
    public ResultData(MessageEnum msg, Object data) {
        this.code = msg.getCode();
        this.msg = msg.getDesc();
        this.data = data;
    }
    //自定义异常封装
    public ResultData(ApolloException e) {
        this.code = e.getMessageEnum().getCode();
        this.msg = e.getMessageEnum().getDesc()+e.getBizMsg();
        this.data=e.getBizMsg();
    }
    //系统异常封装
    public ResultData(Exception e) {
        e.printStackTrace();
        this.code = MessageEnum.SYSTEM_INTERNAL_ERROR.getCode();
        this.msg ="系统异常";

    }




    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
